﻿@using StackExchange.Opserver.Data.Redis
@using Roles = StackExchange.Opserver.Models.Roles
@model RedisInstance
@{
    Layout = null;
    var info = Model;
    var cache = info.Info;
}
<div class="redis-info">
    @if (cache != null)
    {
        if (cache.ErrorMessage.HasValue())
        {
            <div class="last-success-notice">@cache.ErrorMessage</div>
        }
        if (cache.LastPoll > cache.LastSuccess)
        {
            <div class="last-success-notice">Query failed, showing info from: @cache.LastSuccess.ToRelativeTimeSpanMini()</div>
        }
    }
    @if (cache.HasData())
    {
        foreach (var s in cache.Data.Sections)
        {
            var ks = s as RedisInfo.KeyspaceInfo;
            if (ks != null)
            {
<div class="info-title">@s.Name <span class="count">(@s.Lines.Count)</span></div>
<div class="info-section collapsed">
    @foreach (var l in ks.KeyData)
    {
<div class="info-line"><span class="label">DB @l.Key</span>: <span class="value">@l.Value.Keys.ToComma()</span> <span class="note">keys</span> <span class="value">@l.Value.Expires.ToComma()</span> <span class="note">exp</span>@if(Current.User.IsInRole(Roles.RedisAdmin)){ <span class="note">(<a href="/redis/analyze/memory?node=@info.Host:@info.Port&db=@l.Key" class="node-name-link">analyze</a>)</span>}</div>
    }
</div>
            } 
            else 
            {
<div class="info-title">@s.Name</div>
<div class="info-section">
    @foreach (var l in s.Lines)
    {
<div class="info-line@(l.Important ? " important" : "")"><span class="label">@l.Key</span>: <span class="value">@l.ParsedValue</span></div>
    }
</div>}

        }
    }
</div>